<link rel="stylesheet" href="{$Think.const.HOME_CSS}theme.blue.css">
<h1>查询成绩</h1>
<div id="cont">
	<if condition="$role_id == 1">
		<div class="table-head clearfix">
			<div class="wrap left">
				<span>学期：</span>
				<select name="" id="term-select" class="term-select">
					<foreach name="term_info" item="v">
						<option value="{$v.id}" {$v['id'] == $term_id ? 'selected' : ''}>{$v.name}</option>
					</foreach>
				</select>
				<span>班级：</span>
				<select name="" id="class-select" class="class-select">
					<foreach name="class_info" item="v">
						<option value="{$v.id}" {$v['id'] == $class_id ? 'selected' : ''}>{$v.name}</option>
					</foreach>
				</select>
			</div>
			<a href="{:U('Score/addInfo')}" class="input-btn right">录入信息</a>
		</div>
		<script>
			$(function(){
				$('#class-select').change(function(){
					window.location.href = "{:U('Score/showList')}" + "?class_id=" + $(this).val() + '&term_id=' + "{$term_id}";
				});
				$('#term-select').change(function(){
					window.location.href = "{:U('Score/showList')}" + "?class_id=" + "{$class_id}" + "&term_id=" + $(this).val();
				});
			});
		</script>
	<else />
		<span>学期：</span>
		<select name="" id="term-select" class="term-select">
			<foreach name="term_info" item="v">
				<option value="{$v.id}" {$v['id'] == $term_id ? 'selected' : ''}>{$v.name}</option>
			</foreach>
		</select>
	</if>
	<table id="table" class="table tablesorter-blue">
		<thead>
			<tr>
				<th>学号</th>
				<th>名字</th>
				<foreach name="course_info" item="v">
					<th style="color: #336699;">{$v.name}</th>
				</foreach>
				<th style="color: #336699">总分</th>
			</tr>
		</thead>
		<tbody>
			<foreach name="student_info" item="v">
				<tr>
					<td>{$v.id}</td>
					<td>{$v.name}</td>
					<foreach name="course_info" item="sub">
						<td style="color: #339933;">{$v['id']|getScore=###,$sub['id'],$term_id}</td>
					</foreach>
					<td></td>
				</tr>
			</foreach>
		</tbody>
	</table>
</div>
<script src="{$Think.const.HOME_JS}jquery.tablesorter.js"></script>
<script>
	$(function(){

		$('#term-select').change(function(){
			window.location.href = "{:U('Score/showList')}" + "?term_id=" + $(this).val();
		});

		// 计算总分数
		$('tr').each(function(key,value){
			var count = 0;
			for(var i=2; i < 8; i++) {
				count += parseInt($(value).find('td').eq(i).text());
			}
			$(value).find('td').eq(8).text(count);
		});

		// 启用table排序功能,并指定第二列不能用于排序
		$("#table").tablesorter({headers:{1:{sorter:false}}});
	});
</script>

